﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using RegisterationCommon.Common;
using System.Text.RegularExpressions;
using System.Security.Cryptography;
using System.Text;
using System.IO;
using RegisterationCommon.Student;
namespace RegisterationSystem.Space_Student
{
    public partial class findpassword : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {
            //判断验证码是否正确
            if (Convert.ToString(Session["RBVerifiCode"]).ToLower() != this.VerifCode.Text.ToLower())
            {
                Message.Send(10337);
                return;
            }
            string result = "IDCardNumber='" + this.txtIDCardNumber.Text.Trim()+"'" + " and TrueName='" + this.txtname.Text.Trim()+"'" + " and FirstGuardianName='" + txtFirstGuardianName.Text+"'";
            DataTable studentpaw = DBAction.GetDTFromSQL("Select ID From " + ETableName.Students + " where " + result);
            if (studentpaw.Rows.Count > 0)
            {
                this.findpasswordinfo.Visible = true;
                this.studentinfo.Visible = false;
                if (UpdStudentPswdReset(studentpaw.Rows[0]["ID"].ToString(), "123456"))
                {
                    this.resultinfo.Text = "123456";
                }
                
            }
            else
            {
                this.Literal1.Text = "<script>$(function () {alert('您的信息输入不正确');location.reload();});</script>";
                //this.findpasswordinfo.Visible = true;
                //this.studentinfo.Visible = false;
                //this.resultinfo.Text = "您的信息输入不对";
                //this.studengpaw.Visible = false;
            }
        }
        //根据id重置学生帐号密码
      public bool UpdStudentPswdReset(string studentid,string paw)
        {
            string id = studentid;
            string StudentPswd = paw;
            StudentInfo s = new StudentInfo();
          bool flag=s.MdfAccountPwd(Convert.ToInt64(id), BaseLibrary.ConvertToMD5(StudentPswd.ToLower()));
          return flag;
        }
    }
}